package com.ruoyi.web.controller.warehouseManagement;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WarehouseManagement;
import com.ruoyi.system.service.IWarehouseManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 仓库管理 Controller
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@Api(tags="仓库管理")
@RestController
@RequestMapping("/system/warehouseManagement")
public class WarehouseManagementController extends BaseController
{
    @Autowired
    private IWarehouseManagementService warehouseManagementService;

    /**
     * 通过仓库名称和状态查询仓库管理列表
     */
    @ApiOperation("通过仓库名称和状态查询仓库管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String warehouseName,@RequestParam (required = false) String status)
    {
        startPage();
        List<WarehouseManagement> list = warehouseManagementService.selectWarehouseManagementListByName(warehouseName,status);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理列表
     */
    @ApiOperation("导出仓库管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String warehouseName,@RequestParam (required = false) String status)
    {
        List<WarehouseManagement> list = warehouseManagementService.selectWarehouseManagementListByName(warehouseName,status);
        ExcelUtil<WarehouseManagement> util = new ExcelUtil<WarehouseManagement>(WarehouseManagement.class);
        util.exportExcel(response, list, "仓库管理数据");
    }

    /**
     * 通过id获取仓库管理详细信息
     */
    @ApiOperation("通过id获取仓库管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(warehouseManagementService.selectWarehouseManagementById(id));
    }

    /**
     * 新增仓库管理
     */
    @ApiOperation("新增仓库管理")
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseManagement warehouseManagement)
    {
        return toAjax(warehouseManagementService.insertWarehouseManagement(warehouseManagement));
    }

    /**
     * 修改仓库管理
     */
    @ApiOperation("修改仓库管理")
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseManagement warehouseManagement)
    {
        return toAjax(warehouseManagementService.updateWarehouseManagement(warehouseManagement));
    }

    /**
     * 通过id批量删除仓库管理信息
     */
    @ApiOperation("通过id批量删除仓库管理信息")
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(warehouseManagementService.deleteWarehouseManagementByIds(ids));
    }
}
